import { EventEmitter } from "events";
export interface Selection{
    /**开始偏移量 */
    anchor:number,
    /**结束偏移量 */
    focus:number,
}
/**选区模型 */
export class SelectionModel extends EventEmitter {
    private _selection:Selection = {
        anchor:0,
        focus:0
    };
    constructor() {
        super()
        this._selection= { anchor: 0, focus: 0 }
    }
    getSelection():Selection {
        return { ...this._selection }
    }
    setSelection(selection:Selection) {
        if (selection && this._selection && selection.anchor === this._selection.anchor && selection.focus === this._selection.focus) {
            return
        }
        this._selection = selection ? { ...selection } : { anchor:0, focus:0}
    }

    isCollapse ():Boolean{
        return this._selection && this._selection.anchor === this._selection.focus
    }

    isBackward ():Boolean{
        return this._selection && this._selection.anchor > this._selection.focus
    }
}
export default SelectionModel;